//
//  Tracker.swift
//  PDF2PNG
//
//  Created by Jarvis on 12/05/2017.
//  Copyright © 2017 Jarvis. All rights reserved.
//

import UIKit

// talking data appkey
let td_appkey = "FEFF9CF5D3374FCAA359C29E053396DC"
// 分享组件的appkey
let extension_appkey = "591596108f4a9d61f0000064"
// 发布渠道
let channel_id = "App Store"

// AVOSCloud
let av_appKey = "TUwsgb0JCpcldX9S5T0EN6Ae"
let av_appID =  "Q7CwT4566YCXSi3JjTa7lo4o-gzGzoHsz"
let av_masterKey = "tET9kvrRFxxSSU7FyRQDstRz"

//MARK: extension app
// 错误信息
let eventid_share_error = "share_error"
// 错误的文件类型
let eventid_share_error_type = "share_error_type"
let eventid_share_error_save = "share_error_save"

// 加载成功
let eventid_file_loading_success = "file_loading_success"
// 文件保存成功
let eventid_file_save_success = "file_save_success"
// 文件保存
let eventid_file_save = "file_save"
// 文件取消
let eventid_file_cancel = "file_cancel"
// 结果点击OK
let eventid_result_ok = "result_ok"


//MARK: host app
// 刷新文档列表
let eventid_refresh_list = "refresh_list"
// 打开文档（上报文档名
let eventid_open_doc = "open_doc"
// 预览文档页
let eventid_preview_pages = "preview_pages"
// 分享单页（上报文档名
let eventid_share_page = "share_page"
// 开启选择
let eventid_enable_select = "select_pages"
// 禁用选择
let eventid_disable_select = "select_pages"
// 全选
let eventid_select_all_pages = "select_pages"
// 全不选
let eventid_deselect_all_pages = "deselect_all_pages"
// 合并选中页（上报合并页数、总页数
let eventid_merge_pages = "merge_pages"
// 分享拼接的图片（上报图片尺寸、大小
let eventid_share_merged_image = "share_merged_image"

// 用户反馈
let eventid_feedback = "feedback"

class Tracker: NSObject {
    
    //MARK: 页面统计
    class func pageBegin(_ pageName: String) {
        TalkingData.trackPageBegin(pageName)
    }
    
    class func pageEnd(_ pageName: String) {
        TalkingData.trackPageEnd(pageName)
    }
    
    
    //MARK: 事件统计
    class func event(_ eventId: String) {
        TalkingData.trackEvent(eventId)
    }
    
    class func event(_ eventId: String, label: String) {
        TalkingData.trackEvent(eventId, label: label)
    }
    
    class func event(_ eventId: String, label: String, params: [String:String]) {
        TalkingData.trackEvent(eventId, label: label, parameters: params)
    }
    
    
    class func fileLoadingSuccess() {
        Tracker.event(eventid_file_loading_success)
    }
    
    class func fileSave() {
        Tracker.event(eventid_file_save)
    }
    
    
    class func fileCancel() {
        Tracker.event(eventid_file_cancel)
    }
    
    class func fileSaveSuccess() {
        Tracker.event(eventid_file_save_success)
    }
    
    class func resultOK() {
        Tracker.event(eventid_result_ok)
    }
    
    class func fileShareError(reason: String) {
        Tracker.event(eventid_share_error, label: reason)
    }
    
    
    //MARK: host app
    class func refreshList() {
        Tracker.event(eventid_refresh_list)
    }
    
    class func openDoc(docName: String) {
        Tracker.event(eventid_open_doc, label: docName)
    }
    
    class func previewPages() {
        Tracker.event(eventid_preview_pages)
    }
    
    class func sharePage(docName: String) {
        Tracker.event(eventid_share_page, label: docName)
    }
    
    class func enableSelect() {
        Tracker.event(eventid_enable_select)
    }
    
    class func disableSelect() {
        Tracker.event(eventid_disable_select)
    }
    
    class func selectAllPages() {
        Tracker.event(eventid_select_all_pages)
    }
    
    class func deselectAllPages() {
        Tracker.event(eventid_deselect_all_pages)
    }
    
    class func mergePages(numOfPages: Int, totalOfPages: Int) {
        
        let atrributes = ["numOfPages": String(format: "%d", numOfPages),
                          "totalOfPages": String(format: "%d", totalOfPages)]
        
        Tracker.event(eventid_merge_pages, label: "default", params: atrributes)
    }
    
    class func shareMergedImage(imageWidth: Int64, imageHeight: Int64, dataSize: Int64) {
        
        let atrributes = ["imageWidth": String(format: "%d", imageWidth),
                          "imageHeight":String(format: "%d", imageHeight),
                          "dataSize": String(format: "%d", dataSize)]
        
        Tracker.event(eventid_share_merged_image, label: "default", params: atrributes)
    }
    
    class func feedback(message: String) {
        Tracker.event(eventid_feedback, label: message)
    }
    
}
